package com.applet.controller;

import com.applet.Base.BaseController;
import com.applet.annotation.SystemControllerLog;
import com.applet.entity.request.*;
import com.applet.entity.response.GetLockInfoResponse;
import com.applet.entity.response.GetLockInfosResponse;
import com.applet.service.LockService;
import com.applet.utils.AppletResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(value="智能锁controller",tags={"智能锁操作接口"})
public class LockController extends BaseController {

    @Autowired
    private LockService lockService;

    @ApiOperation(value="获取锁信息")
    @SystemControllerLog(funcionExplain = "获取锁信息")
    @PostMapping(value = "/get/lockInfo")
    public AppletResult<GetLockInfoResponse> getLockInfo(HttpServletRequest request,
                                                         @RequestBody GetLockInfoRequest getLockInfoRequest){
        getLockInfoRequest = (GetLockInfoRequest) headUtil.getAllReqHead(request,getLockInfoRequest);
        return lockService.getLockInfo(getLockInfoRequest);
    }

    @ApiOperation(value="绑定锁信息")
    @SystemControllerLog(funcionExplain = "绑定锁信息")
    @PostMapping(value = "/binding/lock")
    public AppletResult bindingLock(HttpServletRequest request,
                                    @RequestBody BindingLockRequest bindingLockRequest){
        bindingLockRequest = (BindingLockRequest) headUtil.getAllReqHead(request,bindingLockRequest);
        return lockService.bindingLock(bindingLockRequest);
    }

    @ApiOperation(value="获取锁列表信息")
    @SystemControllerLog(funcionExplain = "获取锁列表信息")
    @PostMapping(value = "/get/lockInfos")
    public AppletResult<GetLockInfosResponse> getLockInfos(HttpServletRequest request,
                                                           @RequestBody GetLockInfosRequest getLockInfosRequest){
        getLockInfosRequest = (GetLockInfosRequest) headUtil.getAllReqHead(request,getLockInfosRequest);
        return lockService.getLockInfos(getLockInfosRequest);
    }

    @ApiOperation(value="重命名锁")
    @SystemControllerLog(funcionExplain = "重命名锁")
    @PostMapping(value = "/rename/lock")
    public AppletResult renameLock(HttpServletRequest request,
                                   @RequestBody RenameLockRequest renameLockRequest){
        renameLockRequest = (RenameLockRequest) headUtil.getAllReqHead(request,renameLockRequest);
        return lockService.renameLock(renameLockRequest);
    }

    @ApiOperation(value="解除锁绑定")
    @SystemControllerLog(funcionExplain = "解除锁绑定")
    @PostMapping(value = "/remove/lock")
    public AppletResult removeLock(HttpServletRequest request,
                                   @RequestBody RemoveLockRequest removeLockRequest){
        removeLockRequest = (RemoveLockRequest) headUtil.getAllReqHead(request,removeLockRequest);
        return lockService.removeLock(removeLockRequest);
    }
}
